/**
 * Copyright (c) 2012 Axa Holding Belgium, SA. All rights reserved.
 * This software is the confidential and proprietary information of the AXA Group.
 */
package chabernac.android.wordbattle.rastersolver;

import java.util.LinkedHashSet;
import java.util.Set;

import junit.framework.TestCase;
import chabernac.android.wordbattle.db.CommentWordFilter;
import chabernac.android.wordbattle.db.CompositeWordFilter;
import chabernac.android.wordbattle.db.DataBaseLoader;
import chabernac.android.wordbattle.db.InMemoryTreeDB;
import chabernac.android.wordbattle.db.InvalidWordFilter;
import chabernac.android.wordbattle.db.LengthWordFilter;
import chabernac.android.wordbattle.db.URLWordLoader;
import chabernac.android.wordbattle.db.iStringDatabase;
import chabernac.android.wordbattle.db.iWordFilter;
import chabernac.android.wordbattle.db.iWordLoader;
import chabernac.android.wordbattle.model.WordRaster;
import chabernac.android.wordbattle.model.WordRasterFactory;

public class WordRasterSolverTest extends TestCase {
  private iStringDatabase myStringDatabase = new InMemoryTreeDB();
  private iWordLoader myWordLoader = new URLWordLoader( "http://wordbattle.googlecode.com/files" );
  private iWordFilter myWordFilter = new CompositeWordFilter().addFilter( new CommentWordFilter() ).addFilter( new LengthWordFilter( 3, 4 ) ).addFilter( new InvalidWordFilter() );

  
  public void testWordRasterSolver(){
    DataBaseLoader theDatabaseLoader = new DataBaseLoader( myWordLoader, myWordFilter, myStringDatabase, 10000);
    theDatabaseLoader.loadLanguage( "nl" );
    
    WordRaster theRaster = new WordRasterFactory( myStringDatabase ).createBoggleRaster( "nl", 5, 5,  myStringDatabase);
    System.out.println(theRaster);
    
    Set<String> theWords = theRaster.getWordsInRaster();
    for(String theWord : theWords){
      System.out.println(theWord);
    }
  }
  
  public void testHashSet(){
    Set<String> theHashSet = new LinkedHashSet<String>();
    
    StringBuilder theBuilder = new StringBuilder();
    theBuilder.append( 'E' );
    theBuilder.append( 'E' );
    theBuilder.append( 'K' );
    theHashSet.add( theBuilder.toString() );
    
    theBuilder = new StringBuilder();
    theBuilder.append( 'E' );
    theBuilder.append( 'E' );
    theBuilder.append( 'K' );
    theHashSet.add( theBuilder.toString() );
    
    
    theBuilder = new StringBuilder();
    theBuilder.append( 'E' );
    theBuilder.append( 'E' );
    theBuilder.append( 'K' );
    theHashSet.add( theBuilder.toString() );

    assertEquals( 1, theHashSet.size() );
  }
}
